<template>
  <div class="container">
    <div class="left-contain">
      <div class="top-operation">
        <div>
          <el-button
            icon="el-icon-back"
            size="medium"
            type="text"
            @click="goBack"
            >返回</el-button
          >
        </div>
      </div>
      <div class="content">
        <div class="ziliao">
          <div class="ziliao-title">
            <div class="ziliao-name" v-if="mediaInfo">
              {{ mediaInfo.mediaName }}
            </div>
            <div>
              <el-button
                type="primary"
                icon="el-icon-download"
                @click="download(mediaInfo)"
                >下载文件</el-button
              >
            </div>
          </div>
          <div class="player">
            <file-show
              v-if="mediaInfo"
              :media-type="mediaInfo.mediaType"
              :play-path="mediaInfo.playPath"
              :poster-path="mediaInfo.posterPath"
            ></file-show>
          </div>
        </div>
        <div class="ziliao-detail">
          <el-tabs v-model="activeName">
            <el-tab-pane label="基础信息" name="first">
              <div class="meizi" v-if="mediaInfo">
                <media-info
                  v-if="mediaInfo"
                  :media-type="mediaInfo.mediaType"
                  :info="mediaInfo"
                ></media-info>
              </div>
              <div v-else>暂无数据</div>
            </el-tab-pane>
            <el-tab-pane label="编目信息" name="second">
              <description-bian-mu
                v-if="mediaInfo"
                :data="mediaInfo"
              ></description-bian-mu>
              <div v-else>暂无数据</div>
              <!-- <el-form
                :inline="true"
                v-if="formData"
                ref="detailForm"
                label-width="90px"
              >
                <form-item-group
                  style="width: 100%; height: 100%"
                  :form-data="formData"
                  type="detail"
                  item-width="45%"
                  ref="formGroup"
                >
                </form-item-group>
              </el-form> -->
            </el-tab-pane>
          </el-tabs>
        </div>
      </div>
    </div>
    <div class="right-contain">
      <h3>标签</h3>
      <div class="key-word">
        <el-tag
          size="small"
          v-for="(item, index) in words"
          :key="index"
          :closable="false"
          >{{ item }}</el-tag
        >
        <el-empty v-if="words.length === 0" :image-size="200"></el-empty>
      </div>
    </div>
  </div>
</template>
<script>
import FormItemGroup from '@/components/FormItemGroup/index';
import FileShow from '@/components/FileShow';
import MediaInfo from './MediaInfo';
import DescriptionBianMu from './DescriptionBianMu.vue';
import {
  detail as localDetail,
  getLabel as localLabel,
  download as localDownload,
} from '@/api/serve/media-local';
import {
  detail as teamDetail,
  getLabel as teamLabel,
  download as teamDownload,
} from '@/api/serve/media-team';
import {
  detail as publicDetail,
  getLabel as publicLabel,
  download as publicDownload,
} from '@/api/serve/media-search';
import {
  detail as flowDetail,
  getLabel as flowLabel,
} from '@/api/serve/media-flow';
import Download from '@/views/_mixins/download';
export default {
  name: 'itemDetail',
  mixins: [Download],
  components: {
    FileShow,
    FormItemGroup,
    MediaInfo,
    DescriptionBianMu,
  },
  data() {
    return {
      filePath: filePath,
      mediaId: '',
      activeName: 'first',
      words: [],
      mediaInfo: null,
      imgSrc: '',
      entry: 'public',
      loading: false,
    };
  },
  created() {
    let mediaId = this.$route.query.mediaId;
    this.initFuc(mediaId);
  },
  methods: {
    initFuc(mediaId) {
      this.mediaInfo = null;
      this.words = [];
      this.activeName = 'first';
      // this.initFormData();

      this.mediaId = mediaId;
      // this.posterPath = data.posterPath;
      this.getMediaDetail(this.mediaId);
      this.getLabel();
    },
    download(mediaInfo) {
      this.loading = true;
      let that = this;
      that.$message('正在下载中...');
      let inter = setInterval(() => {
        that.$message('正在下载中...');
      }, 4000);
      if (this.entry === 'team') {
        teamDownload(mediaInfo.mediaId).then((res) => {
          this.downloadFile(res.data[0], mediaInfo.mediaName, inter);
        });
      }
      if (this.entry === 'local') {
        localDownload(mediaInfo.mediaId).then((res) => {
          this.downloadFile(res.data[0], mediaInfo.mediaName, inter);
        });
      }
      if (this.entry === 'public') {
        publicDownload(mediaInfo.mediaId).then((res) => {
          this.downloadFile(res.data[0], mediaInfo.mediaName, inter);
        });
      }
    },
    //获取标签
    getLabel() {
      if (this.entry === 'team') {
        teamLabel(this.mediaId).then((res) => {
          this.words = res;
        });
      }
      if (this.entry === 'local') {
        localLabel(this.mediaId).then((res) => {
          this.words = res;
        });
      }
      if (this.entry === 'public') {
        publicLabel(this.mediaId).then((res) => {
          this.words = res;
        });
      }
      if (this.entry === 'check') {
        flowLabel(this.mediaId).then((res) => {
          this.words = res;
        });
      }
    },
    getMediaDetail(mediaId) {
      if (this.entry === 'team') {
        teamDetail(mediaId).then((res) => {
          this.mediaInfo = res;
        });
      }
      if (this.entry === 'local') {
        localDetail(mediaId).then((res) => {
          this.mediaInfo = res;
        });
      }
      if (this.entry === 'public') {
        publicDetail(mediaId).then((res) => {
          this.mediaInfo = res;
        });
      }
      if (this.entry === 'check') {
        flowDetail(mediaId).then((res) => {
          this.mediaInfo = res;
        });
      }
    },
    goBack() {
      // this.$router.go(-1);
      //this.$parent.pButton2(0);
      // 返回集下载统计
      console.log('pageOrigin...', this.$route.query.pageOrigin);
      if (this.$route.query.pageOrigin) {
        // this.$router.push({
        //   path: '/infor-search',
        // });
        this.$router.go(-1);
        return false;
      }
      this.$router.go(-1);
      // this.$router.push({
      //   path: '/download-stats/mediaDownDetails',
      // });
    },
    /**
     * 初始化表单数据
     * */
    initFormData() {
      this.formData = {
        mediaName: '',
        mediaAlias: '',
        organId: '',
        catalogName: '',
        mediaFigure: '',
        completeTime: '',
        mediaDes: '',
      };
    },
  },
};
</script>
<style lang="scss" scoped>
.container {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: space-between;
  .left-contain {
    width: 74%;
    height: 100%;
    background: #ffffff;
    // box-shadow: 0px 2px 13px 0px rgba(0, 0, 0, 0.06);
    border-radius: 6px;
    padding: 25px 23px;
    display: flex;
    flex-direction: column;
    .top-operation {
      margin-bottom: 15px;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    .content {
      margin-top: 10px;
      height: calc(100% - 51.5px);
      display: flex;
      flex-direction: column;
      align-items: center;
      .ziliao {
        width: 95%;
        height: 70%;
        display: flex;
        flex-direction: column;
        .ziliao-title {
          // margin-bottom: 10px;
          // height: 24px;
          display: flex;
          justify-content: space-between;
          margin-bottom: 8px;
          .ziliao-name {
            font-size: 18px;
            font-family: MicrosoftYaHeiSemibold;
            color: #2d2d2d;
            line-height: 24px;
          }
          .ziliao-data {
            font-size: 12px;
            font-family: MicrosoftYaHei;
            color: #8c8c8c;
            line-height: 16px;
            display: flex;
            align-items: center;
          }
        }
        .player {
          width: 100%;
          height: calc(100% - 40px);
        }
      }
      .ziliao-detail {
        width: 95%;
        height: 30%;
        ::v-deep .el-tabs {
          width: 100%;
          height: 100%;
          display: flex;
          flex-direction: column;
          .el-tabs__content {
            width: 100%;
            height: calc(100% - 54px);
            .el-tab-pane {
              width: 100%;
              height: 100%;
            }
          }
        }
        .meizi {
          width: 100%;
          height: 100%;
          display: flex;
          .meizi-left {
            width: 25%;
            height: 100%;
            display: flex;
            flex-direction: column;
            .meizi-pic {
              flex: 1;
            }
          }
          .meizi-center {
            width: 25%;
            height: 100%;
            padding-left: 10px;
            display: flex;
            flex-direction: column;
            justify-content: center;
          }
          .meizi-right {
            width: 50%;
            height: 100%;
            display: flex;
            flex-direction: column;
            .meizi-content {
              height: calc(100% - 20px);
              // border: 1px dashed #d9d9d9;
              overflow-y: auto;
            }
          }
        }
      }
    }
  }
  .right-contain {
    width: 25%;
    height: 100%;
    background: #ffffff;
    box-shadow: 0px 2px 13px 0px rgba(0, 0, 0, 0.06);
    border-radius: 6px;
    padding: 0 16px;
    .key-word {
      margin-bottom: 10px;
    }
  }
}
.el-tag {
  margin-right: 16px;
  margin-bottom: 8px;
}
::v-deep .el-descriptions-item__label.has-colon::after {
  display: none;
}
</style>
